package cn.com.api.controller;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import cn.com.api.entity.ApiSmslog;
import cn.com.api.entity.ApiT_member;
import cn.com.api.entity.ApiT_member_entrepreneur;
import cn.com.api.entity.ApiT_member_idcard;
import cn.com.api.entity.ApiT_member_task_process;
import cn.com.api.entity.ApiTmember;
import cn.com.api.entity.ApiU_message;
import cn.com.api.entity.ApiU_see_his;
import cn.com.api.entity.ApiU_user_experence;
import cn.com.api.entity.ApiU_user_friend;
import cn.com.api.entity.ApiU_user_label;
import cn.com.api.entity.MemberObject;
import cn.com.api.entity.U_label;
import cn.com.api.entity.memberHomePage;
import cn.com.api.mapper.ApiShopsMapper;
import cn.com.api.mapper.ApiTmemberMapper;
import cn.com.api.service.ApiMemberService;
import cn.com.api.service.ApiSmslogService;
import cn.com.api.service.ApiT_cityService;
import cn.com.api.service.ApiT_memberService;
import cn.com.api.service.ApiT_member_idcardService;
import cn.com.api.service.ApiU_circle_memberService;
import cn.com.api.service.ApiU_messageService;
import cn.com.api.service.ApiU_see_hisService;
import cn.com.api.service.ApiU_user_experenceService;
import cn.com.api.service.ApiU_user_friendService;
import cn.com.api.service.ApiU_user_labelService;
import cn.com.api.service.ApiUploadService;
import cn.com.api.service.CheckService;
import cn.com.api.service.StartOnLoadService;
import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_API + "member/")
public class ApiMemberController {

	@Autowired
	private ApiMemberService apiMemberService;
	@Autowired
	private ApiT_memberService memberService;
	@Autowired
	private ApiSmslogService apiSmslogService;
	@Autowired
	private CheckService checkService;
	@Autowired
	private ApiT_cityService apiT_cityService;
	@Autowired
	private StartOnLoadService startOnLoadService;
	@Autowired
	private ApiTmemberMapper apiTmemberMapper;
	@Autowired
	private ApiShopsMapper apiShopsMapper;
	@Autowired
	private ApiU_user_labelService apiUserLabelService;
	@Autowired
	private ApiT_member_idcardService apiT_member_idcardService;
	@Autowired
	private ApiU_user_experenceService apiU_user_experenceService;
	@Autowired
	private ApiU_user_friendService apiU_user_friendService;
	@Autowired
	private ApiU_messageService apiU_messageService;
	@Autowired
	private ApiU_see_hisService apiU_see_hisService;
	@Autowired
	private ApiT_memberService apiT_memberService;
	@Autowired
	private ApiU_circle_memberService apiU_circle_memberService;
	@Autowired
	private ApiUploadService apiUploadService;

	private static Logger logger = LogManager
			.getLogger(ApiMemberController.class.getName());

	/**
	 * 根据会员编码获取会员名称
	 */
	@RequestMapping(value = "getMemberInfoByMembercode")
	public void getMemberInfoByMembercode(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String membercode = request.getParameter("membercode");
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			map = apiMemberService.getMemberInfoByMembercode(membercode);
		} catch (Exception e) {
			logger.error("回去会员信息失败：" + Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 注册-验证码 identifying code 1-判断手机是否注册过 2-发送验证码 3-存储 4-返回json信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "identify")
	public void identifyCode(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String cTel = request.getParameter("cMob");
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			if (cTel != null && !"".equals(cTel.trim())) {
				if (apiMemberService.checkMemberExist(cTel) == null) {// 未注册过
					// 注册，发验证码，插入数据库
					String random = apiMemberService.sendIdentifyCode(cTel, 0);// 0-用户注册
					// 根据random 判断输入的手机是否发送成功
					if (random.length() > 0) {
						map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
						map.put(Utils.MESSAGE, "验证码发送成功");
						Map<String, Object> datas = new HashMap<String, Object>();
						datas.put("code", random);
						map.put("datas", datas);
					} else {
						map.put(Utils.RESULT, "0003");
						map.put(Utils.MESSAGE, "手机号不正确，发送不成功！");
					}
				} else {
					map.put(Utils.RESULT, "0003");
					map.put(Utils.MESSAGE, "手机号已注册，请直接登录！");
				}
			} else {
				map.put(Utils.RESULT, "0008");
				map.put(Utils.MESSAGE, "手机号码不能为空！");
			}
		} catch (Exception e) {
			logger.error(Util.getStackTraceAsString(e) + ",发送验证码失败，手机号：" + cTel);
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 注册
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "register")
	public void register(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {

			String cMob = request.getParameter("cMob");// 用户名-手机号
			String code = request.getParameter("code");// 验证码
			String cPass = request.getParameter("cPass");// 密码

			String nickname = request.getParameter("nickname");// 昵称
			String realName = request.getParameter("realName");// 真实姓名
			String cwx = request.getParameter("cwx");// 微信号
			String cqq = request.getParameter("cqq");// qq号
			String id_back = request.getParameter("idcard_back");// 身份证背面图片
			String id_front = request.getParameter("idcard_face");// 身份证正面图片

			String invitecode = request.getParameter("invitecode");// 邀请人的邀请码
			String proxyid = request.getParameter("proxyid");// 代理等级
			String membercode = request.getParameter("membercode");// 上线的会员编码
			String payimgurl = request.getParameter("payimgurl");// 缴费凭证
			String deviceId = request.getParameter("deviceId");// 设备id
			String deviceType = request.getParameter("deviceType");// 设备类型：0:IOS;1:Android

			ApiTmember member = new ApiTmember();
			member.setCuserid(cMob);// 首次注册用户名=用户id
			member.setCmob(cMob);// 手机号
			member.setCpass(CipherUtil.generatePassword(cPass));
			member.setCnick(nickname);
			member.setCtname(realName);

			member.setCmtype(0);// 0-用户
			member.setCwx(cwx);
			member.setCqq(cqq);
			member.setC_invitecode(invitecode);
			member.setC_proxyid(Integer.valueOf(proxyid));
			member.setC_superior(membercode);
			member.setDeviceid(deviceId);
			member.setDevicetype(Integer.parseInt(deviceType));

			ApiSmslog apiSmslog = new ApiSmslog();
			apiSmslog.setcTel(cMob);
			apiSmslog.setCode(code);

			ApiT_member_idcard idcard = new ApiT_member_idcard();
			idcard.setId_front(id_front);
			idcard.setId_back(id_back);
			idcard.setName(realName);
			idcard.setId_type(1);// 身份证

			map = apiMemberService.registmember(member, idcard, apiSmslog,
					payimgurl);
		} catch (Exception e) {
			logger.error("用户注册:" + Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 登录
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@Transactional
	@RequestMapping(value = "login")
	public void login(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String cMob = request.getParameter("cMob");
			String cPass = request.getParameter("cPass");
			String Longitude = request.getParameter("cLongitude");// 经
			String Latitude = request.getParameter("cLatitude");// 纬
			String deviceId = request.getParameter("deviceId");// 设备id
			String deviceType = request.getParameter("deviceType");// 设备类型：：0:IOS

			ApiTmember member = new ApiTmember();
			member.setCmob(cMob);
			member.setCuserid(cMob);
			member.setCpass(CipherUtil.generatePassword(cPass));
			if (!Util.isNull(Longitude)) {
				member.setLongitude(Longitude);
				member.setLatitude(Latitude);
			}

			if (!Util.isNull(deviceType)) {
				member.setDeviceid(deviceId);
				member.setDevicetype(Integer.valueOf(deviceType));
			}

			ApiTmember apiMember = apiMemberService.login(member);
			if (apiMember != null) {
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "登录成功");
				// 将用户信息返回
				map.put(Utils.DATAS, apiMember);
			} else {
				map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				map.put(Utils.MESSAGE, "帐号或密码错误");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
	//-----------------------------------------------------------------------------------

	/**
	 * 微信端领红包
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "wxreceivebonus")
	public void wxreceivebonus(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String cMob = request.getParameter("cMob");// 用户名-手机号
			String code = request.getParameter("code");// 验证码
			String bonus_detail_id = request.getParameter("bonus_detail_id");// 红包id
			map = apiMemberService.wxreceivebonus(cMob, code, bonus_detail_id);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 验证码登录发送验证码
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "loginCode")
	public void loginCode(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String cTel = request.getParameter("cMob");
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			if (cTel != null && !"".equals(cTel.trim())) {

				//
				String random = apiMemberService.sendIdentifyCode(cTel, 0);// 0-用户注册
				if (random.length() > 0) {
					map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
					map.put(Utils.MESSAGE, "验证码发送成功");
					Map<String, Object> datas = new HashMap<String, Object>();
					datas.put("code", random);
					map.put("datas", datas);
				} else {
					map.put(Utils.RESULT, "0003");
					map.put(Utils.MESSAGE, "手机号码不正确,发送不成功！");
				}
			} else {
				map.put(Utils.RESULT, "0008");
				map.put(Utils.MESSAGE, "手机号码不能为空！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		// response.setCharacterEncoding("UTF-8");
		// PrintWriter out = response.getWriter();
		// out.write(JsonUtil.object2json(map));
		// out.close();
		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 验证码直接登录
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@Transactional
	@RequestMapping(value = "loginByCode")
	public void loginByCode(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String cMob = request.getParameter("cMob");// 用户名-手机号
			String code = request.getParameter("code");// 验证码

			String deviceId = request.getParameter("deviceId");// 设备id
			String deviceType = request.getParameter("deviceType");// 设备类型：0:IOS
																	// 1:Android

			ApiTmember member = new ApiTmember();
			member.setCuserid(cMob);// 首次注册用户名=用户id
			member.setCmob(cMob);// 手机号

			Date now = new Date();
			SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyy/MM/dd HH:mm:ss");
			member.setCregdate(dateFormat.format(now));
			member.setCmtype(0);// 0-用户
			member.setClogdate(dateFormat.format(now));
			member.setIs_login(1);
			member.setCnick(cMob);
			// member.setCtname(cMob);

			// member.setInvite_code(invite_code);
			if (!Util.isNull(deviceType)) {
				member.setDeviceid(deviceId);
				member.setDevicetype(Integer.parseInt(deviceType));
			}
			ApiSmslog apiSmslog = new ApiSmslog();
			apiSmslog.setcTel(cMob);
			apiSmslog.setCode(code);

			// 校验验证码是否正确
			if (apiSmslogService.checkCode(apiSmslog)) {
				String realpath = ImageUtils.getServletWebAppsPath(request)
						.replace("/B2B4Shoumei", ImageUtils.IMAGE_ROOT);
				// 注册
				ApiTmember Nmember = apiMemberService.loginByCode(realpath,
						member, apiSmslog);

				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "注册成功");
				map.put("datas", Nmember);
			} else {
				map.put(Utils.RESULT, "0002");
				map.put(Utils.MESSAGE, "验证码不匹配，请重新填写！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 用户忘记密码-发送验证码
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@Transactional
	@RequestMapping(value = "forget")
	public void forget(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String cMob = request.getParameter("cMob");
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			if (cMob != null && !"".equals(cMob.trim())) {
				// 判断手机号是否已注册，未注册提示用户新账号
				ApiTmember member = apiMemberService.checkMemberExist(cMob);
				if (member != null) {// 注册过
					String random = apiMemberService.sendIdentifyCode(
							member.getCmob(), 1);// 1-用户忘记密码
					map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
					map.put(Utils.MESSAGE, "验证码发送成功");
					Map<String, Object> datas = new HashMap<String, Object>();
					datas.put("code", random);
					map.put("datas", datas);
				} else {
					map.put(Utils.RESULT, "0003");
					map.put(Utils.MESSAGE, "手机号未注册，请注册！");
				}

			} else {
				map.put(Utils.RESULT, "0008");
				map.put(Utils.MESSAGE, "手机号不能为空！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		// response.setCharacterEncoding("UTF-8");
		// PrintWriter out = response.getWriter();
		// out.write(JsonUtil.object2json(map));
		// out.close();
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 商铺忘记密码-发送验证码
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@Transactional
	@RequestMapping(value = "shopforget")
	public void shopforget(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String cMob = request.getParameter("cMob");
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			if (cMob != null && !"".equals(cMob.trim())) {
				// 判断手机号是否已注册，未注册提示用户新账号
				if (apiMemberService.checkShopsExist(cMob)) {// 注册过
					String random = apiMemberService.sendIdentifyCode(cMob, 2);// 2-商户忘记密码
					map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
					map.put(Utils.MESSAGE, "验证码发送成功");
					Map<String, Object> datas = new HashMap<String, Object>();
					datas.put("code", random);
					map.put("datas", datas);
				} else {
					map.put(Utils.RESULT, "0003");
					map.put(Utils.MESSAGE, "手机号未注册，请注册！");
				}

			} else {
				map.put(Utils.RESULT, "0008");
				map.put(Utils.MESSAGE, "手机号不能为空！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	// -------------------------用户个人信息模块---------------------
	/**
	 * 根据userid返回用户信息
	 * 
	 * @throws Exception
	 */
	@RequestMapping(value = "personalinfo")
	public void getPersonalInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Integer finish_per = 0;

			String cUserId = request.getParameter("user_id");// 用户ID

			String token = request.getParameter("token");
			Map<String, String> params = new HashMap<String, String>();
			params.put("u_id", cUserId);
			params.put("token", token);

			if (checkService.checkToken(cUserId, token, map)
					&& checkService.checkParams(params, map)) {
				ApiTmember member = apiMemberService.findMemberByCid(Integer
						.valueOf(cUserId));

				map.put("datas", member);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "获取成功");
				// 计算完成率
				Integer finishCount = 0;
				if (!Util.isNull(member.getCavatar())
						&& !member.getCavatar().equals("")) {
					finishCount++;
				}
				if (!Util.isNull(member.getCnick())
						&& !member.getCnick().equals("")) {
					finishCount++;
				}
				if (!Util.isNull(member.getCtname())
						&& !member.getCtname().equals("")) {
					finishCount++;
				}
				if (!Util.isNull(member.getCbirthday())
						&& !member.getCbirthday().equals("")) {
					finishCount++;
				}
				if (!Util.isNull(member.getCsex())
						&& !member.getCsex().equals("")) {
					finishCount++;
				}
				if (!Util.isNull(member.getCarea())
						&& !member.getCarea().equals("")) {
					finishCount++;
				}
				if (!Util.isNull(member.getCompany_title())
						&& !member.getCompany_title().equals("")) {
					finishCount++;
				}
				if (!Util.isNull(member.getProfession_title())
						&& !member.getProfession_title().equals("")) {
					finishCount++;
				}
				if (!Util.isNull(member.getIs_Interest())
						&& member.getIs_Interest() > 0) {
					finishCount++;
				}
				if (!Util.isNull(member.getIs_Area())
						&& member.getIs_Area() > 0) {
					finishCount++;
				}
				finish_per = finishCount * 100 / 10;

			}
			map.put("finish_per", finish_per + "%");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		// response.setCharacterEncoding("UTF-8");
		// PrintWriter out = response.getWriter();
		// out.write(JsonUtil.object2json(map));
		// out.close();
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 根据userid返回用户信息
	 * 
	 * @throws Exception
	 */
	@RequestMapping(value = "personalinfoNoToken")
	public void personalinfoNoToken(HttpServletRequest request,
			HttpServletResponse response, String user_id) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			ApiTmember member = apiMemberService.findMemberByCid(Integer
					.valueOf(user_id));
			if (member != null) {
				map.put("datas", member);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "获取成功");
			} else {
				map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				map.put(Utils.MESSAGE, "用户不存在");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 用户忘记密码
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@Transactional
	@RequestMapping(value = "forgetCPass")
	public void forgetCPass(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String cMob = request.getParameter("cMob");// 用户名-手机号
		String code = request.getParameter("code");// 验证码
		String cPass = request.getParameter("cPass");// 新密码
		String cPassTwo = request.getParameter("cPassTwo");// 确认密码
		String deviceId = request.getParameter("deviceId");// 设备id
		String deviceType = request.getParameter("deviceType");// 设备类型：0:IOS
																// 1:Android
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			if (cPass != null && !"".equals(cPass) && cPass.equals(cPassTwo)) {
				// 忘记密码接口，先查询用户，更新用户密码信息，更新验证码信息 返回用户信息
				ApiTmember member = apiMemberService.findMemberByCuserid(cMob);
				member.setCpass(CipherUtil.generatePassword(cPass));// 设置新密码
				Date now = new Date();
				SimpleDateFormat dateFormat = new SimpleDateFormat(
						"yyyy/MM/dd HH:mm:ss");
				member.setClogdate(dateFormat.format(now));
				if (!Util.isNull(deviceType)) {
					member.setDeviceid(deviceId);
					member.setDevicetype(Integer.parseInt(deviceType));
				}
				ApiSmslog apiSmslog = new ApiSmslog();
				apiSmslog.setcTel(member.getCmob());
				apiSmslog.setCode(code);
				// 注册 校验验证码是否正确
				if (apiSmslogService.checkCode(apiSmslog)) {
					apiMemberService.forgetCPass(member, apiSmslog);
					map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
					map.put(Utils.MESSAGE, "操作成功");
					map.put("datas", member);
				} else {
					map.put(Utils.RESULT, "0002");
					map.put(Utils.MESSAGE, "验证码不匹配，请重新填写！");
				}

			} else {
				map.put(Utils.RESULT, "0002");
				map.put(Utils.MESSAGE, "两次密码不一致，请重新填写！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		// response.setCharacterEncoding("UTF-8");
		// PrintWriter out = response.getWriter();
		// out.write(JsonUtil.object2json(map));
		// out.close();
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 个人资料 跟个人中心查的数据一样
	 */
	@RequestMapping(value = "getPersonalMsg")
	public void getPersonalMsg(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String cUserId = request.getParameter("cMob");
			String token = request.getParameter("token");
			Map<String, String> params = new HashMap<String, String>();
			params.put("u_id", cUserId);
			params.put("token", token);
			if (checkService.checkToken(cUserId, token, map)
					&& checkService.checkParams(params, map)) {
				ApiTmember member = apiMemberService
						.findMemberByCuserid(cUserId);
				map.put("datas", member);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "操作成功");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		// response.setCharacterEncoding("UTF-8");
		// PrintWriter out = response.getWriter();
		// out.write(JsonUtil.object2json(map));
		// out.close();
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 个人资料修改 姓名、年龄、性别----我的头像是地址
	 */
	@RequestMapping(value = "modifyPersonalMsg")
	public void modifyPersonalMsg(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String cUserId = request.getParameter("user_id");// 用户ID
			String token = request.getParameter("token");
			String key = request.getParameter("key");// key: ctname,cage,csex
			String value = request.getParameter("value");
			Map<String, String> params = new HashMap<String, String>();
			params.put("u_id", cUserId);
			params.put("token", token);
			params.put("key", key);
			params.put("value", value);
			if (checkService.checkToken(cUserId, token, map)
					&& checkService.checkParams(params, map)) {
				Map<String, Object> paramMap = new HashMap<String, Object>();
				paramMap.put("cid", cUserId);

				if ("cnick".equals(key)) {
					paramMap.put("cnick", value);
				}
				if ("cavatar".equals(key)) {
					paramMap.put("cavatar", value);
				}
				if ("ctname".equals(key)) {
					paramMap.put("ctname", value);
				}
				if ("cbirthday".equals(key)) {
					paramMap.put("cbirthday", value);
				}
				if ("csex".equals(key)) {
					paramMap.put("csex", value);
				}
				// 拆分地址
				if ("addr_string".equals(key)) {
					String addr[] = value.split("%");
					paramMap.put("cprovince", addr[0]);
					paramMap.put("ccity", addr[1]);
					paramMap.put("carea", addr[2]);
				}
				// if ("cprovince".equals(key)) {
				// paramMap.put("cprovince", value);
				// }
				// if ("ccity".equals(key)) {
				// paramMap.put("ccity", value);
				// }
				// if ("carea".equals(key)) {
				// paramMap.put("carea", value);
				// }
				if ("company_title".equals(key)) {
					paramMap.put("company_title", value);
				}
				if ("profession_title".equals(key)) {
					paramMap.put("profession_title", value);
				}

				apiMemberService.modifyApiTmemberByCuserid(paramMap);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "修改成功！");
			} else {
				// RESULT_RC_CHECK_FAIL
				map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				map.put(Utils.MESSAGE, "帐号或密码错误");
				// 将用户信息返回
				// map.put("datas", null);
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	private String updateHeaderImg(MultipartFile file,
			HttpServletRequest request, String user_id, String pictureType) {
		String filePathNew = "";
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
			String date = sdf.format(new Date());// 年月
			String realpath = ImageUtils.getServletWebAppsPath(request)
					.replace(request.getContextPath(), ImageUtils.IMAGE_ROOT)
					+ "/Header_image/" + date + "/";// 获取服务器路径

			System.out.println("Server filePath-----" + realpath);// -------------上传的服务器路径

			// -------------上传的服务器路径
			// 生产的图片名称：
			// 文件夹不存在 则创建
			File headPath = new File(realpath);// 获取文件夹路径
			if (!headPath.exists()) {// 判断文件夹是否创建，没有创建则创建新文件夹
				headPath.mkdirs();
			}

			String dateTime = new Date().getTime() + "";
			String pictureName = user_id + "_" + dateTime + "." + pictureType;

			file.transferTo(new File(realpath + pictureName));

			filePathNew = "/Header_image/" + date + "/" + pictureName;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
		}
		return filePathNew;
	}

	/**
	 * 微信端 个人资料修改 姓名、年龄、性别----我的头像是上传(另写一个接口)
	 */
	@RequestMapping(value = "modifyPersonalAllMsg")
	// public void modifyPersonalAllMsg(@RequestParam(value = "file")
	// MultipartFile file, HttpServletRequest request, HttpServletResponse
	// response) throws Exception {
	public void modifyPersonalAllMsg(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String cUserId = request.getParameter("user_id");// 用户ID
			String token = request.getParameter("token");
			// 头像
			// String pictureType = request.getParameter("pictureType");
			String cavatar = request.getParameter("file");
			String cnick = request.getParameter("cnick");
			String ctname = request.getParameter("ctname");
			String cbirthday = request.getParameter("cbirthday");
			String csex = request.getParameter("csex");
			String addr_string = request.getParameter("addr_string");
			String company_title = request.getParameter("company_title");
			String profession_title = request.getParameter("profession_title");

			Map<String, String> params = new HashMap<String, String>();
			params.put("cid", cUserId);
			params.put("token", token);
			params.put("cavatar", cavatar);
			params.put("cnick", cnick);
			params.put("ctname", ctname);
			params.put("cbirthday", cbirthday);
			params.put("csex", csex);
			params.put("addr_string", addr_string);
			params.put("company_title", company_title);
			params.put("profession_title", profession_title);

			if (checkService.checkToken(cUserId, token, map)
					&& checkService.checkParams(params, map)) {
				// 头像更新
				String headFilePath = "";
				// if(!Util.isNull(file) && !Util.isNull(pictureType))
				// {
				// headFilePath = updateHeaderImg(file, request, cUserId,
				// pictureType);
				// }

				Map<String, Object> paramMap = new HashMap<String, Object>();
				paramMap.put("cid", cUserId);
				paramMap.put("cavatar", cavatar);
				paramMap.put("cnick", cnick);
				paramMap.put("ctname", ctname);
				paramMap.put("cbirthday", cbirthday);
				paramMap.put("csex", csex);
				// 拆分地址
				String addr[] = addr_string.split(":");
				paramMap.put("cprovince", addr[0]);
				paramMap.put("ccity", addr[1]);
				paramMap.put("carea", addr[2]);

				paramMap.put("company_title", company_title);
				paramMap.put("profession_title", profession_title);

				apiMemberService.modifyApiTmemberByCuserid(paramMap);
				map.clear();
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put("headerPath", headFilePath);
				map.put(Utils.MESSAGE, "修改成功！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 个人资料修改 姓名、年龄、性别----我的头像是上传(另写一个接口)
	 */
	@RequestMapping(value = "updateShipperPersonInfo")
	public void updateShipperPersonInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Map<String, Object> paramMap = new HashMap<String, Object>();
			String cUserId = request.getParameter("cUserId");
			String token = request.getParameter("token");
			Map<String, String> params = new HashMap<String, String>();
			params.put("u_id", cUserId);
			params.put("token", token);
			if (checkService.checkToken(cUserId, token, map)
					&& checkService.checkParams(params, map)) {
				if (!Util.isNull(cUserId)) {
					paramMap.put("cid", cUserId);
				}
				String address = request.getParameter("address");
				if (!Util.isNull(address)) {
					paramMap.put("caddress", address);
				}
				String ctname = request.getParameter("ctname");
				if (!Util.isNull(ctname)) {
					paramMap.put("ctname", ctname);
				}
				apiMemberService.modifyApiTmemberByCuserid(paramMap);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "修改成功！");
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 上传头像
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "upload")
	public void UploadAvatar(@RequestParam(value = "file") MultipartFile file,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String u_id = request.getParameter("user_id");
			String token = request.getParameter("token");
			String pictureType = request.getParameter("pictureType");
			Map<String, String> para = new HashMap<String, String>();
			para.put("u_id", u_id);
			para.put("token", token);
			if (checkService.checkToken(u_id, token, map)
					&& checkService.checkParams(para, map)) {
				System.out.println(request.getSession().getServletContext()
						.getRealPath(""));// 参数可具体到包名。
				MultipartFile[] files = { file };
				List<String> urlList = apiUploadService.uploadFileToServer(
						files,request,"/member/");

				// SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
				// String date = sdf.format(new Date());// 年月
				// String realpath =
				// ImageUtils.getServletWebAppsPath(request).replace(request.getContextPath(),
				// ImageUtils.IMAGE_ROOT) + "/Header_image/" + date + "/";//
				// 获取服务器路径
				//
				// System.out.println("Server filePath-----" + realpath);//
				// -------------上传的服务器路径
				//
				// // -------------上传的服务器路径
				// // 生产的图片名称：
				// // 文件夹不存在 则创建
				// File headPath = new File(realpath);// 获取文件夹路径
				// if (!headPath.exists()) {// 判断文件夹是否创建，没有创建则创建新文件夹
				// headPath.mkdirs();
				// }
				//
				// String dateTime = new Date().getTime() + "";
				// String pictureName = u_id + "_" + dateTime + "." +
				// pictureType;
				//
				// file.transferTo(new File(realpath + pictureName));
				//
				// String filePathNew = "/Header_image/" + date + "/" +
				// pictureName;
				String filePathNew = urlList.get(0);
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("cid", u_id);
				params.put("cavatar", filePathNew);// cUserId
				apiMemberService.modifyApiTmemberByCuserid(params);

				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "上传成功!");
				map.put("filePath", filePathNew);
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	@RequestMapping("upload2")
	public void handleFileUpload(
			@RequestParam(value = "file") MultipartFile file,
			HttpServletRequest request) throws IllegalStateException,
			IOException {
		System.out.println(">>>>>>>>>>>>");
		file.transferTo(new File("D:/1.jpg"));
	}

	// 第三方登陆新加↓↓↓↓
	// 第三方登陆
	@RequestMapping(value = "thirdLogin")
	public void thirdLogin(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		System.out.println("第三方账号登陆。。。。");
		Map<String, Object> map = new HashMap<String, Object>();
		// String thirdUsername = request.getParameter("thirdUsername");//
		// String thirdHeaderImage =
		// request.getParameter("thirdHeaderImage");//不需要了--头像不需要
		String openId = request.getParameter("openId");
		String type = request.getParameter("type");
		String thirdName = request.getParameter("thirdName");
		String deviceId = request.getParameter("deviceId");// 设备id
		String deviceType = request.getParameter("deviceType");// 设备类型：0:IOS
																// 1:Android
		// 1-QQ 2-微信 3-新浪
		try {
			if (!Util.isNull(type)) {
				if ("3".equals(type) || "1".equals(type) || "2".equals(type)) {
					Map<String, String> params = new HashMap<String, String>();
					params.put("openId", openId);
					params.put("type", type);
					params.put("thirdName", thirdName);
					params.put("deviceId", deviceId);
					params.put("deviceType", deviceType);

					ApiTmember apiMember = apiMemberService
							.isExistThirdLogin(params);
					if (apiMember == null) {// 不存在，则插入
						apiMember = new ApiTmember();
						apiMember.setThirdType(Integer.valueOf(type));

						apiMember.setThirdToken(openId);
						map.put("datas", apiMember);
						map.put("is_success", "0");
						map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
						map.put(Utils.MESSAGE, "未绑定手机号，需要绑定手机号或注册！");// 可绑定已有帐号或注册
					} else {
						map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
						map.put(Utils.MESSAGE, "登录成功！");
						map.put("is_success", "1");
						// 将用户信息返回
						map.put("datas", apiMember);
					}
				} else {
					map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
					map.put(Utils.MESSAGE, "第三方登录方式错误！");
					// 将用户信息返回
					map.put("datas", null);
				}
			}
		} catch (Exception e) {
			logger.error(Util.getStackTraceAsString(e));
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	// 第三方登陆新加↑↑↑↑

	/**
	 * 第三方登陆时获取验证码
	 * 接口：http://139.196.171.69/webmvc/api/member/thirdIdentity?cMob=15821285717
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "thirdIdentity")
	public void thirdIdentity(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String cTel = request.getParameter("cMob");
		Map<String, Object> map = new HashMap<String, Object>();

		try {
			if (cTel != null && !"".equals(cTel.trim())) {
				Map<String, Object> datas = new HashMap<String, Object>();
				// 查询手机号是否已注册
				if (apiMemberService.checkMemberExist(cTel) == null) {// 未注册过,不可绑定手机号
					datas.put("is_register", "0");
					datas.put("code", "00000");
				} else {
					// 已注册
					String random = apiMemberService.sendIdentifyCode(cTel, 0);// 0-用户注册
					map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
					map.put(Utils.MESSAGE, "操作成功");

					datas.put("code", random);
					datas.put("is_register", "1");
				}
				map.put("datas", datas);
			} else {
				map.put(Utils.RESULT, "0003");
				map.put(Utils.MESSAGE, "手机号码不能为空！");
			}
		} catch (Exception e) {
			logger.error(Util.getStackTraceAsString(e));
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 绑定手机
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "bindingPhone")
	public void bindingPhone(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		System.out.println("绑定手机号....");
		// String is_register = request.getParameter("is_register");
		String c_mob = request.getParameter("cMob");
		String code = request.getParameter("code");
		String cPass = request.getParameter("cPass");
		String thirdName = request.getParameter("thirdName");
		// String invite_code = request.getParameter("invite_code");//邀请码
		String openId = request.getParameter("openId");
		String type = request.getParameter("type");
		String Longitude = request.getParameter("cLongitude");// 经
		String Latitude = request.getParameter("cLatitude");// 纬
		String deviceId = request.getParameter("deviceId");// 设备id
		String deviceType = request.getParameter("deviceType");// 设备类型：0:IOS
																// 1:Android
		Map<String, Object> map = new HashMap<String, Object>();

		try {
			if (c_mob != null && !"".equals(c_mob.trim())) {
				Map<String, String> params = new HashMap<String, String>();
				// params.put("is_register", is_register);
				params.put("cMob", c_mob);
				params.put("code", code);
				params.put("thirdName", thirdName);
				params.put("cPass", cPass);
				params.put("openId", openId);
				params.put("type", type);

				if (!Util.isNull(deviceType)) {
					params.put("deviceId", deviceId);
					params.put("deviceType", deviceType);
				}
				if (!Util.isNull(Latitude)) {
					params.put("Longitude", Longitude);
					params.put("Latitude", Latitude);
				}
				// params.put("invite_code", invite_code);
				String realpath = ImageUtils.getServletWebAppsPath(request)
						.replace("/B2B4Shoumei", ImageUtils.IMAGE_ROOT);
				apiMemberService.thirdFirstLogin(realpath, params, map);

			} else {
				map.put(Utils.RESULT, "0008");
				map.put(Utils.MESSAGE, "手机号码不能为空！");
			}
		} catch (Exception e) {
			logger.error(Util.getStackTraceAsString(e));
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		// response.setCharacterEncoding("UTF-8");
		// PrintWriter out = response.getWriter();
		// out.write(JsonUtil.object2json(map));
		// out.close();
		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 定位县市
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "locationCity")
	public void locationCity(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String address = request.getParameter("address");
		String latitude = request.getParameter("latitude");
		String longitude = request.getParameter("longitude");
		logger.info("初始化定位附近开通城市：经度：" + longitude + "--纬度：" + latitude);

		Map<String, Object> map = new HashMap<String, Object>();

		try {
			if (address != null && !"".equals(address.trim())) {

				Map<String, Object> result_map = new HashMap<String, Object>();
				result_map = apiT_cityService.getNearbyCity(
						Float.valueOf(latitude), Float.valueOf(longitude));
				Object distance = result_map.get("distance");
				Float distance2 = Float.valueOf(distance.toString());
				// 大于30公里表示当前地理位置未开通,定位的附近的 已开通城市
				System.out.println("距离最近开通城市的距离：" + distance2);
				logger.info("查询到最近开通城市的距离：" + distance2);
				String open_distance_str = startOnLoadService.dictionaryMap()
						.get("open_distance".toUpperCase());
				Float open_distance = Float.valueOf(open_distance_str);
				logger.info("查询到最近开通城市的距离：" + distance2 + "  数据库配置距离："
						+ open_distance);
				System.out.println("-----------查询到最近开通城市的距离："
						+ Utils.GetDistance("28.170113", "113.649567",
								"31.197773", "121.447087"));
				if (distance2 > open_distance)
					result_map.put("opened_status", "未开通");
				else
					result_map.put("opened_status", "已开通");

				map.put("datas", result_map);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "定位附近城市成功！");
			}
		} catch (Exception e) {
			logger.error(Util.getStackTraceAsString(e));
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 设备id type 更新存储----用户端、配送端可用
	 */
	@RequestMapping(value = "upateUserDevice")
	public void upateUserDevice(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String u_id = request.getParameter("u_id");
		String deviceId = request.getParameter("deviceId");// 设备id
		String deviceType = request.getParameter("deviceType");// 设备类型：0:IOS
																// 1:Android
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			if (!Util.isNull(u_id)) {
				ApiTmember member = apiMemberService.findMemberByCuserid(u_id);
				if (member != null) {
					member.setDeviceid(deviceId);
					member.setDevicetype(Integer.parseInt(deviceType));
					apiTmemberMapper.updateApiTmember(member);
					map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
					map.put(Utils.MESSAGE, "操作成功");
				}
			} else {
				map.put(Utils.RESULT, "0002");
				map.put(Utils.MESSAGE, "用户名为空！");
			}

		} catch (Exception e) {
			logger.error(Util.getStackTraceAsString(e));
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 退出登录，更新标识
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "exitLogin")
	public void exitLogin(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();

		try {
			String u_id = request.getParameter("u_id");
			String shop_id = request.getParameter("shop_id");

			if (!Util.isNull(u_id)) {
				apiTmemberMapper.updateLoginFlagByUid(Integer.valueOf(u_id), 0);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "操作成功");
			} else if (!Util.isNull(shop_id)) {
				apiShopsMapper.updateLoginFlagBySid(shop_id, 0);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "操作成功");
			}
		} catch (Exception e) {
			logger.error(Util.getStackTraceAsString(e));
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		// response.setCharacterEncoding("UTF-8");
		// PrintWriter out = response.getWriter();
		// out.write(JsonUtil.object2json(map));
		// out.close();
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	@RequestMapping(value = "shareInfo")
	public @ResponseBody
	Map<String, Object> shareInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String userid = request.getParameter("userid");
		return memberService.shareInfoById(userid);

	}

	/**
	 * 我的档案--兴趣爱好
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "searchUserInfoExtend")
	public void searchUserInfoExtend(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();

		try {
			String cUserId = request.getParameter("user_id");// 用户ID，T_member表中c_id字段

			String token = request.getParameter("token");
			String type = request.getParameter("type"); // 1兴趣分类，2订阅分类
			Map<String, String> params = new HashMap<String, String>();
			params.put("u_id", cUserId);
			params.put("token", token);

			if (checkService.checkToken(cUserId, token, map)
					&& checkService.checkParams(params, map)) {

				List<U_label> labs = apiMemberService.searchUserInfoExtend(
						Integer.valueOf(cUserId), Integer.valueOf(type));
				if (labs != null) {
					map.put(Utils.DATAS, labs);
					map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
					map.put(Utils.MESSAGE, "操作成功");
				} else {
					map.put(Utils.DATAS, null);
					map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
					map.put(Utils.MESSAGE, "系统异常！");
				}
			} else {
				map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				map.put(Utils.MESSAGE, "帐号或密码错误");
				map.put(Utils.DATAS, null);
			}

		} catch (Exception e) {
			logger.error(Util.getStackTraceAsString(e));
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		// response.setCharacterEncoding("UTF-8");
		// PrintWriter out = response.getWriter();
		// out.write(JsonUtil.object2json(map));
		// out.close();
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 我的档案--兴趣爱好
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "setUserInfoExtend")
	public void setUserInfoExtend(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();

		try {
			String cUserId = request.getParameter("user_id");// 用户ID，T_member表中c_id字段
			String token = request.getParameter("token");
			String type = request.getParameter("type"); // 1兴趣分类，2订阅分类

			String cate_id = request.getParameter("parent_id");// 父ID,多个用%分隔
			String cate_name = request.getParameter("parent_name");// 多个用%分隔

			String label_id = request.getParameter("label_id");// 多个用%分隔
			String label_name = request.getParameter("label_name");// 多个用%分隔
			Map<String, String> params = new HashMap<String, String>();
			params.put("u_id", cUserId);
			params.put("token", token);
			params.put("type", type);
			params.put("parent_id", cate_id);
			params.put("parent_name", cate_name);
			params.put("label_id", label_id);
			params.put("label_name", label_name);

			if (checkService.checkToken(cUserId, token, map)
					&& checkService.checkParams(params, map)) {

				List<ApiU_user_label> listLab = new ArrayList<ApiU_user_label>();

				String cate_ids[] = cate_id.split(":");
				String cate_names[] = cate_name.split(":");
				String label_ids[] = label_id.split(":");
				String label_names[] = label_name.split(":");

				if (cate_ids.length != cate_names.length
						|| label_ids.length != label_names.length
						|| cate_names.length != label_ids.length) {
					// Error
					map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
					map.put(Utils.MESSAGE, "参数传入异常！");
				} else {
					for (int i = 0; i < cate_ids.length; i++) {
						ApiU_user_label uLabel = new ApiU_user_label();
						uLabel.setCate_id(cate_ids[i]);
						uLabel.setCate_name(cate_names[i]);
						uLabel.setLabel_id(label_ids[i]);
						uLabel.setLabel_name(label_names[i]);
						uLabel.setUser_id(cUserId);
						uLabel.setType(Integer.valueOf(type));
						listLab.add(uLabel);
					}

					boolean ret = apiUserLabelService.setUserInfoExtend(
							listLab, cUserId, Integer.valueOf(type));
					if (ret) {
						map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
						map.put(Utils.MESSAGE, "更新完成");
					} else {
						map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
						map.put(Utils.MESSAGE, "更新失败！");
					}
				}

			}
			// else
			// {
			// map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			// map.put(Utils.MESSAGE, "帐号或密码错误");
			// map.put("datas", null);
			// }

		} catch (Exception e) {

			logger.error(Util.getStackTraceAsString(e));
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		// response.setCharacterEncoding("UTF-8");
		// PrintWriter out = response.getWriter();
		// out.write(JsonUtil.object2json(map));
		// out.close();
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	@RequestMapping(value = "modifyPassword")
	public void modifyPassword(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String cUserId = request.getParameter("user_id");// 用户ID
			String token = request.getParameter("token");
			String cPass = request.getParameter("cPass");// 密码
			String cNewPass = request.getParameter("cNewPass");// 确认密码
			String ctype = request.getParameter("ctype");// 0:修改密码， 1：设置密码

			Map<String, String> params = new HashMap<String, String>();
			params.put("u_id", cUserId);
			params.put("token", token);
			if (ctype.equals("0")) {
				params.put("cPass", cPass);
			}
			params.put("cNewPass", cNewPass);
			if (checkService.checkToken(cUserId, token, map)
					&& checkService.checkParams(params, map)) {
				if (ctype.equals("0")) {
					if (apiMemberService.CheckUser(Integer.valueOf(cUserId),
							CipherUtil.generatePassword(cPass)) != null) {
						Map<String, Object> paramMap = new HashMap<String, Object>();
						paramMap.put("cid", cUserId);
						paramMap.put("cpass",
								CipherUtil.generatePassword(cNewPass));

						apiMemberService.modifyApiTmemberByCuserid(paramMap);
						map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
						map.put(Utils.MESSAGE, "修改成功！");
					} else {
						map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
						map.put(Utils.MESSAGE, "帐号或密码错误");
						map.put("datas", null);
					}
				} else {
					Map<String, Object> paramMap = new HashMap<String, Object>();
					paramMap.put("cid", cUserId);
					paramMap.put("cpass", CipherUtil.generatePassword(cNewPass));

					apiMemberService.modifyApiTmemberByCuserid(paramMap);
					map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
					map.put(Utils.MESSAGE, "设置成功！");
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 身份认证
	 * 
	 * @param apiT_member_idcard 接收身份认证信息的实体类
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 */
	@RequestMapping(value = "identityAttestation")
	public void identityAttestation(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token,
			ApiT_member_idcard apiT_member_idcard) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Map<String, String> paramMap = new HashMap<String, String>();
			paramMap.put("u_id", user_id);
			paramMap.put("token", token);
			if (checkService.checkToken(user_id, token, map)
					&& checkService.checkParams(paramMap, map)) {
				map.clear();
				map = apiT_member_idcardService
						.identityAttestation(apiT_member_idcard);
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 获取用户的身份认证信息
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 */
	@RequestMapping(value = "getMemberIdentity")
	public void getMemberIdentity(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Map<String, String> paramMap = new HashMap<String, String>();
			paramMap.put("u_id", user_id);
			paramMap.put("token", token);
			if (checkService.checkToken(user_id, token, map)
					&& checkService.checkParams(paramMap, map)) {
				map.put("user_id", user_id);
				List<ApiT_member_idcard> apiT_member_idcard = apiT_member_idcardService
						.findT_member_idcardByMap(map);
				if (apiT_member_idcard != null && apiT_member_idcard.size() > 0) {
					map.put(Utils.DATAS, apiT_member_idcard.get(0));
				} else {
					map.put(Utils.DATAS, null);
				}
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "操作成功");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 扫描二维码
	 * 
	 * @param qrcode 二维码(类型:编码)(类型 0加好友，1邀请核伙人，2？？？) 邀请核伙人二维码参数样式：核伙人 1:认证编码，
	 * 加好友0:好友ID
	 * 
	 * @param user_id 用户ID
	 * 
	 * @param token
	 */
	@RequestMapping(value = "scanQRcode")
	public void scanQRcode(HttpServletRequest request,
			HttpServletResponse response, String qrcode, String user_id,
			String token) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {

			Map<String, String> params = new HashMap<String, String>();
			params.put("u_id", user_id);
			params.put("token", token);
			params.put("qrcode", qrcode);

			if (checkService.checkToken(user_id, token, map)
					&& checkService.checkParams(params, map)) {
				ApiTmember member = this.apiMemberService
						.findMemberByCid(Integer.valueOf(user_id));
				if (!Util.isNull(member)) {
					String[] codes = qrcode.split(":");
					if (codes.length == 2) {// 格式正确
						String codeType = codes[0];
						String code = codes[1];
						if (codeType.equals("1")) {// 邀请核伙人
							if (member.getReferee_uid().trim().length() == 0) {
								ApiTmember memPartner = apiMemberService
										.findMemberByPartnerCode(code);
								if (memPartner == null) {
									map.put(Utils.RESULT, "0004");
									map.put(Utils.MESSAGE, "邀请码不存在，请确认！");
								} else {
									// 推荐人不能为自己
									if (memPartner.getCid().toString()
											.equals(user_id)) {
										map.put(Utils.RESULT, "0004");
										map.put(Utils.MESSAGE, "邀请人不可为自己，请确认。");
									} else {
										if (memPartner.getVerify_partner() != 1) {
											map.put(Utils.RESULT, "0004");
											map.put(Utils.MESSAGE,
													"邀请人不是核伙人，请确认。");
										} else {
											Map<String, Object> paramMap = new HashMap<String, Object>();
											paramMap.put("cid", user_id);
											paramMap.put("referee_uid", code);

											apiMemberService
													.modifyApiTmemberByCuserid(paramMap);
											map.put(Utils.RESULT,
													Utils.RESULT_RC_SUCCESS);
											map.put("type", "1");
											map.put(Utils.MESSAGE, "添加成功！");
										}
									}
								}
							} else {
								// 已经被别人邀请过
								map.put(Utils.RESULT, "0004");
								map.put(Utils.MESSAGE, "已被邀请过，不可再接收邀请！");
							}
						} else if (codeType.equals("0")) {// 加好友

							ApiTmember f_member = apiMemberService
									.findMemberByCid(Integer.valueOf(code));
							if (f_member != null) {
								// 发加好友请求
								ApiU_user_friend ufriend = this.apiU_user_friendService
										.getUserFriend(user_id, code);
								if (ufriend == null) {
									ApiTmember active_member = this.apiMemberService
											.findMemberByCid(Integer
													.valueOf(user_id));
									// ApiTmember passive_member =
									// this.apiMemberService.findMemberByCid(Integer.valueOf(friend_id));
									ApiU_user_friend user_friend = new ApiU_user_friend();
									user_friend.setFriend_id(code);
									user_friend
											.setF_rename(f_member.getCnick());
									user_friend.setUser_id(user_id);
									user_friend.setU_rename(active_member
											.getCnick());
									user_friend.setAdd_time(Util.CurrentTime());
									user_friend.setIs_deal(0);
									user_friend.setStatus(0);
									user_friend.setMsg("请求加为好友");
									Integer ret = this.apiU_user_friendService
											.U_user_friendInsertion(user_friend);
									if (ret == 1) {
										// 通知对方加好友请求
										ApiU_message message = new ApiU_message();
										message.setConn_id(user_friend.getId());
										message.setType(1);
										message.setAdd_time(Util.CurrentTime());
										message.setIs_read(0);
										message.setUser_id(code);
										message.setTitle("请求加为好友");
										message.setContent("请求加为好友");
										this.apiU_messageService
												.U_messageInsertion(message);
										map.put(Utils.RESULT,
												Utils.RESULT_RC_SUCCESS);
										map.put(Utils.MESSAGE, "操作成功");
										map.put("type", "0");

									} else {
										map.put(Utils.RESULT,
												Utils.RESULT_RC_EXCEPTION);
										map.put(Utils.MESSAGE, "请求加为好友失败！");
									}

								} else {
									// 好友关系状态 0申请中， 1已通过， 2已拒绝, 3黑名单
									if (ufriend.getStatus() == 0
											|| ufriend.getStatus() == 2) {
										ufriend.setAdd_time(Util.CurrentTime());
										ufriend.setStatus(0);
										ufriend.setIs_deal(0);
										ufriend.setMsg("加好友请求！");
										this.apiU_user_friendService
												.updateU_user_friend(ufriend);

										map.put(Utils.RESULT,
												Utils.RESULT_RC_SUCCESS);
										map.put(Utils.MESSAGE, "操作成功");
										map.put("type", "0");
									} else if (ufriend.getStatus() == 1) {
										map.put(Utils.RESULT,
												Utils.RESULT_RC_SUCCESS);
										map.put(Utils.MESSAGE, "已是好友");
									} else {
										map.put(Utils.RESULT,
												Utils.RESULT_RC_PARAMTER_ERROR);
										map.put(Utils.MESSAGE, "参数异常");
									}
								}
							} else {
								map.put(Utils.RESULT, "0004");
								map.put(Utils.MESSAGE, "邀请码不存在，请确认！");
							}
						} else if (codeType.equals("2")) {// 扫描圈子二维码加入圈子
							map = apiU_circle_memberService.joincircle(user_id,
									user_id, code, "申请加入圈子");
						} else {
							// 格式错误
							map.put(Utils.RESULT, "0005");
							map.put(Utils.MESSAGE, "二维码格式不正确，请确认！");
						}

					} else {
						// 格式错误
						map.put(Utils.RESULT, "0005");
						map.put(Utils.MESSAGE, "二维码格式不正确，请确认！");
					}
				} else {
					map.put(Utils.RESULT, Utils.RESULT_RC_PARAMTER_ERROR);
					map.put(Utils.MESSAGE, "参数异常");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	//
	/*
	 * 更新用户首媒号updateSmcodeByUid
	 * 
	 * @param qrcode 二维码(类型:编码)(类型 0加好友，1邀请核伙人，2？？？)
	 * 
	 * @param user_id 用户ID
	 * 
	 * @param token
	 */
	@RequestMapping(value = "UpdateSMCode")
	public void UpdateSMCode(HttpServletRequest request,
			HttpServletResponse response, String sm_code, String user_id,
			String token) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {

			Map<String, String> params = new HashMap<String, String>();
			params.put("u_id", user_id);
			params.put("token", token);
			params.put("sm_code", sm_code);

			if (checkService.checkToken(user_id, token, map)
					&& checkService.checkParams(params, map)) {
				// ApiTmember member =
				// this.apiMemberService.findMemberByCid(Integer.valueOf(user_id));
				// String[] codes = qrcode.split(":");
				ApiTmember member = this.apiMemberService.updateSmcodeByUid(
						Integer.valueOf(user_id), sm_code);
				if (Util.isNull(member)) {
					map.put(Utils.RESULT, "0004");
					map.put(Utils.MESSAGE, "修改失败，请确认！");
				} else {
					map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
					map.put(Utils.MESSAGE, "修改成功！");
					map.put(Utils.DATAS, member);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 查询职业经历
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 */
	@RequestMapping(value = "getExperenceByUserID")
	public void getExperenceByUserID(HttpServletRequest request,
			HttpServletResponse response, String user_id) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Map<String, String> params = new HashMap<String, String>();
			params.put("u_id", user_id);
			// params.put("token", token);

			// if (checkService.checkToken(user_id, token, map) &&
			// checkService.checkParams(params, map)) {
			List<ApiU_user_experence> experenceList = this.apiU_user_experenceService
					.getExperenceByUserID(user_id);
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "操作成功");
			map.put(Utils.DATAS, experenceList);
			// }

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 保存职业经历
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 * 
	 * @param company 公司名
	 * 
	 * @param title 职位
	 * 
	 * @param b_time 开始时间
	 * 
	 * @param e_time 结束时间
	 * 
	 * @param description 描述
	 * 
	 * @param token
	 */
	@RequestMapping(value = "saveExperenceByUserID")
	public void saveExperenceByUserID(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token,
			String company, String title, String b_time, String e_time,
			String description) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Map<String, String> params = new HashMap<String, String>();
			params.put("u_id", user_id);
			params.put("token", token);
			params.put("company", company);
			params.put("title", title);
			params.put("b_time", b_time);
			params.put("e_time", e_time);

			if (checkService.checkToken(user_id, token, map)
					&& checkService.checkParams(params, map)) {
				List<ApiU_user_experence> experenceList = this.apiU_user_experenceService
						.getExperenceByUserID(user_id);
				Integer listCount = experenceList.size();
				ApiU_user_experence uExperence = new ApiU_user_experence();
				uExperence.setCompany(company);
				uExperence.setTitle(title);
				uExperence.setB_time(b_time);
				uExperence.setE_time(e_time);
				uExperence.setDescription(description);
				uExperence.setSort(listCount + 1);
				uExperence.setUser_id(user_id);
				this.apiU_user_experenceService
						.insertU_user_experence(uExperence);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "添加完成！");
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 删除职业经历
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 * 
	 * @param experence_id 经历ID
	 */
	@RequestMapping(value = "delExperenceByID")
	public void delExperenceByID(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token,
			String experence_id) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Map<String, String> params = new HashMap<String, String>();
			params.put("u_id", user_id);
			params.put("token", token);
			params.put("experence_id", experence_id);

			if (checkService.checkToken(user_id, token, map)
					&& checkService.checkParams(params, map)) {

				this.apiU_user_experenceService.deleteU_user_experence(Integer
						.valueOf(experence_id));

				List<ApiU_user_experence> experenceList = this.apiU_user_experenceService
						.getExperenceByUserID(user_id);

				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "删除完成！");
				map.put(Utils.DATAS, experenceList);
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 用户主页
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 * 
	 * @param to_uid 被看人的ID，看自己时传自己id
	 * 
	 * @param type 0:企业主 1：核伙人 2：自媒体 3：自己的主页面 4：别人的主页
	 */
	@RequestMapping(value = "getUserHomePage")
	public void getUserHomePage(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token,
			String type, String to_uid) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Map<String, String> params = new HashMap<String, String>();
			params.put("to_uid", to_uid);

			if (checkService.checkParams(params, map)) {

				memberHomePage homePage = this.apiMemberService
						.getUserHomePageInfo(to_uid, Integer.valueOf(type),
								user_id);

				if (!user_id.equals(to_uid)) {
					// 看谁
					params.clear();
					params.put("user_id", user_id);
					params.put("see_uid", to_uid);

					PageInfo pageInfo = new PageInfo();
					pageInfo.setShowCount(10);
					pageInfo.setCurrentPage(1);
					List<ApiU_see_his> see_List = this.apiU_see_hisService
							.findU_see_hissByMapListPage(params, pageInfo);
					if (see_List == null || see_List.size() == 0) {
						ApiU_see_his see_his = new ApiU_see_his();
						see_his.setUser_id(user_id);
						see_his.setSee_uid(to_uid);
						see_his.setSee_time(Util.CurrentTime());
						see_his.setIs_read(0);
						this.apiU_see_hisService.U_see_hisInsertion(see_his);
					} else {
						ApiU_see_his see_his = see_List.get(0);
						see_his.setSee_time(Util.CurrentTime());
						this.apiU_see_hisService.updateU_see_his(see_his);
					}
				}

				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "操作完成！");
				map.put(Utils.DATAS, homePage);
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 搜索用户(去除黑名单中的)
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 * 
	 * @param to_uid 被看人的ID，看自己时传自己id
	 * 
	 * @param type 0:企业主 1：核伙人 2：自媒体
	 */
	@RequestMapping(value = "findUserByWord")
	public void findUserByWord(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token,
			String word, PageInfo page) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Map<String, String> params = new HashMap<String, String>();
			params.put("word", word);

			if (checkService.checkParams(params, map)) {

				List<ApiTmember> members = this.apiMemberService
						.findMemberByWords(user_id, word, page);

				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "操作完成！");
				map.put(Utils.DATAS, members);
				map.put(Utils.Page, page);
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 主页查看企业主列表
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 * 
	 * @param partner_code 我的认证编码
	 */
	@RequestMapping(value = "getEntrepreneursList")
	public void getEntrepreneursList(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token,
			String partner_code, PageInfo page) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			if (checkService.checkToken(user_id, token, map)) {

				List<MemberObject> obj_members = this.apiMemberService
						.getEntrepreneursList(partner_code, page);

				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "操作完成！");
				map.put(Utils.DATAS, obj_members);
				map.put(Utils.Page, page);
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 主页查看核伙人列表
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 * 
	 * @param partner_code 我的认证编码
	 */
	@RequestMapping(value = "getPartnerList")
	public void getPartnerList(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token,
			String partner_code, PageInfo page) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			if (checkService.checkToken(user_id, token, map)) {

				List<MemberObject> obj_members = this.apiMemberService
						.getPartnerList(partner_code, page);

				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "操作完成！");
				map.put(Utils.DATAS, obj_members);
				map.put(Utils.Page, page);
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 主页企业主列表查看企业信息
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 * 
	 * @param ent_id 企业主申请表ID
	 */
	@RequestMapping(value = "getEntreInfo")
	public void getEntreInfo(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token,
			String ent_id) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			// if (checkService.checkToken(user_id, token, map)) {

			ApiT_member_entrepreneur entre = this.apiMemberService
					.getEntreInfo(ent_id);
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "操作完成！");
			map.put(Utils.DATAS, entre);
			// }

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 主页企业主列表查看圈子信息
	 * 
	 * @param user_id 用户id
	 */
	@RequestMapping(value = "getCircleInfo")
	public void getCircleInfo(HttpServletRequest request,
			HttpServletResponse response, String user_id, PageInfo page)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			// if (checkService.checkToken(user_id, token, map)) {

			List<MemberObject> circle_list = this.apiMemberService
					.getCircleList(user_id, page);
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "操作完成！");
			map.put(Utils.DATAS, circle_list);
			// }

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 主页企业主列表查看动态信息
	 * 
	 * @param user_id 用户id
	 */
	@RequestMapping(value = "getDynamicInfo")
	public void getDynamicInfo(HttpServletRequest request,
			HttpServletResponse response, String user_id, PageInfo page)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			// if (checkService.checkToken(user_id, token, map)) {

			List<MemberObject> dynamic_list = this.apiMemberService
					.getDynamicList(user_id, page);
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "操作完成！");
			map.put(Utils.DATAS, dynamic_list);
			// }

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 保存专业领域
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 * 
	 * @param area 专业领域名
	 */
	@RequestMapping(value = "saveProfessionArea")
	public void saveProfessionArea(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token,
			String area, String certificate) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Map<String, String> params = new HashMap<String, String>();
			params.put("u_id", user_id);
			params.put("token", token);
			params.put("area", area);

			if (checkService.checkToken(user_id, token, map)
					&& checkService.checkParams(params, map)) {
				ApiU_user_label user_label = new ApiU_user_label();
				user_label.setCate_name(area);
				user_label.setUser_id(user_id);
				user_label.setCate_id("-1");
				user_label.setType(3);
				user_label.setExt1(certificate);
				this.apiUserLabelService.insertU_user_label(user_label);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "添加完成！");
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 获取专业领域
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 */
	@RequestMapping(value = "getProfessionArea")
	public void getProfessionArea(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Map<String, String> params = new HashMap<String, String>();
			params.put("user_id", user_id);
			params.put("type", "3");

			if (checkService.checkToken(user_id, token, map)) {
				List<ApiU_user_label> user_label_list = this.apiUserLabelService
						.getUserProfessionArea(params);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "操作成功！");
				map.put(Utils.DATAS, user_label_list);
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 核伙人任务明细
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 */
	@RequestMapping(value = "getPartnerTaskInfo")
	public void getPartnerTaskInfo(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token,
			String process_id) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			// Map<String, String> params = new HashMap<String, String>();
			// params.put("user_id", user_id);
			// params.put("process_id", process_id);

			if (checkService.checkToken(user_id, token, map)) {
				ApiT_member_task_process task_process = this.apiMemberService
						.getMemberPartnerTaskInfo(process_id);
				if (!Util.isNull(task_process)) {
					map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
					map.put(Utils.MESSAGE, "获取成功！");
					map.put(Utils.DATAS, task_process);
				} else {
					map.put(Utils.RESULT, Utils.RESULT_RC_PARAMTER_ERROR);
					map.put(Utils.MESSAGE, "参数异常！");
				}

			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 更换个人主页背景图
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 * 
	 * @param background_url 背景图地址
	 * 
	 * @param type: 0个人主页背景图， 1个人动态背景图
	 */
	@RequestMapping(value = "changeBackground")
	public void changeBackground(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token,
			String background_url, String back_type) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {

			if (checkService.checkToken(user_id, token, map)) {
				Map<String, Object> paramMap = new HashMap<String, Object>();
				paramMap.put("cid", user_id);

				if (back_type.equals("1")) {
					paramMap.put("dynamic_image", background_url);
				} else {
					paramMap.put("back_ground", background_url);
				}
				apiMemberService.modifyApiTmemberByCuserid(paramMap);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "上传成功！");
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 设置修改支付密码
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 */
	@RequestMapping(value = "updatepaypwd")
	public void updatepaypwd(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token,
			String oldpwd, String newpwd) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			if (checkService.checkToken(user_id, token, map)) {
				ApiT_member apiT_member = apiT_memberService
						.findT_memberById(Integer.valueOf(user_id));
				if (!Util.isNull(apiT_member.getPay_pwd())
						&& !"".equals(apiT_member.getPay_pwd())) {// 重新设置密码
					if (apiT_member.getPay_pwd().equals(
							CipherUtil.generatePassword(oldpwd))) {
						apiT_member.setPay_pwd(CipherUtil
								.generatePassword(newpwd));
						apiT_memberService.updateT_member(apiT_member);
						map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
						map.put(Utils.MESSAGE, "操作成功");
					} else {
						map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
						map.put(Utils.MESSAGE, "原密码不正确");
					}
				} else {
					apiT_member.setPay_pwd(CipherUtil.generatePassword(newpwd));
					apiT_memberService.updateT_member(apiT_member);
					map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
					map.put(Utils.MESSAGE, "操作成功");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/*
	 * 忘记支付密码
	 * 
	 * @param user_id 用户id
	 * 
	 * @param token
	 */
	@RequestMapping(value = "forgetpaypwd")
	public void forgetpaypwd(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String cMob = request.getParameter("cMob");// 用户名-手机号
		String code = request.getParameter("code");// 验证码
		String cPass = request.getParameter("cPass");// 新密码

		Map<String, Object> map = new HashMap<String, Object>();
		try {
			ApiTmember member = apiMemberService.findMemberByCuserid(cMob);
			ApiSmslog apiSmslog = new ApiSmslog();
			apiSmslog.setcTel(member.getCmob());
			apiSmslog.setCode(code);
			// 校验验证码是否正确
			if (apiSmslogService.checkCode(apiSmslog)) {
				member.setPay_pwd(CipherUtil.generatePassword(cPass));
				apiMemberService.resetPayPwd(member, apiSmslog);
				map.clear();
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "操作成功");
			} else {
				map.put(Utils.RESULT, "0002");
				map.put(Utils.MESSAGE, "验证码不匹配，请重新填写！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		// response.setCharacterEncoding("UTF-8");
		// PrintWriter out = response.getWriter();
		// out.write(JsonUtil.object2json(map));
		// out.close();
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 是否设置支付密码
	 * 
	 * @author JW
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "isSetPayPwd")
	public void isSetPayPwd(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		Map<String, Object> map = new HashMap<>();
		try {
			ApiT_member member = memberService.getMemberById(request
					.getParameter("userId"));
			if (!Util.isNull(member) && !Util.isNull(member.getPay_pwd())) {
				map.put("hasPayPwd", 1);
			} else {
				map.put("hasPayPwd", 0);
			}
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "查询成功");
		} catch (Exception e) {
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
}
